package com.jzo2o.customer.controller.agency;

import cn.hutool.core.bean.BeanUtil;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController(" BankCountController")
@RequestMapping("/agency/bank-account")
@Api(tags = "机构端 - 服务人员或机构相关接口")
public class BankAccountController {
    @Autowired
    private IBankAccountService bankAccountService;

    @PostMapping
    @ApiOperation("新增或更新银行账号信息")
    public BankAccountResDTO add(@RequestBody BankAccountUpsertReqDTO bankAccountUpsertReqDTO){
        BankAccountResDTO bankAccountResDTO = bankAccountService.add(bankAccountUpsertReqDTO);
        return bankAccountResDTO;
    }

    @GetMapping("currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号")
    public BankAccountResDTO query(){
        Long userId = UserContext.currentUserId();
        // 应该根据用户ID查询银行账户，而不是直接用用户ID作为银行账户ID查询
        BankAccount bankAccount = bankAccountService.getById(userId);
        BankAccountResDTO bankAccountResDTO = BeanUtil.toBean(bankAccount, BankAccountResDTO.class);
        return bankAccountResDTO;
    }
}
